/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interface;

import Cliente.Cliente;
import Cliente.Letras;
import Cliente.StopWatch;
import Cliente.listaEncadeada;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author saracristhina
 */
public class Jogo extends javax.swing.JFrame {

    /**
     * Creates new form Jogo     */
    
Letras letraSorteada;

String[] letras= new String[16];
String[] letrasAleatórias;
String[] armazenadorTemp=new String[30];
Cliente cliente;
String[] conjuntoPalavras;
int contArmazenador=0;
int contador;
boolean jogoAndamento=false;
Object palavrasEnviadas;
String[] dados= new String[16];
 Random random = new Random();
 String palavras = "";
 boolean status=true;
 int cont=0;
 long tempoInicial,tempoFinal;
 
 listaEncadeada lista= new listaEncadeada();
 
    public Jogo() throws UnknownHostException, IOException, ClassNotFoundException {
        this.letraSorteada = new Letras();
        initComponents();
       
        /*Colocando o icone na janela*/
        try{
            Image icon;
            icon = Toolkit.getDefaultToolkit().getImage("src/Imagens/letter_b.jpg");
            setIconImage(icon);
        }catch (Exception e){
            JOptionPane.showMessageDialog(null, e,"Erro!!!", 0);
        }
        /*cor dos backgrounds*/
        Color minhaCor = new Color(129, 175, 238);  
        this.getContentPane().setBackground(minhaCor);
        Color minhacor2 = new Color(22,44,111);
        mostrarTexto.setBackground(minhacor2);
        
        /*Tamanho da janela*/
        this.setVisible(true);
        this.setSize(700, 500); 
        this.setResizable(false); 
        
        /*Alterar a cor das labels desabilitadas*/
        UIManager.put("Label.disabledForeground",Color.BLACK);
                
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        jPanel1 = new javax.swing.JPanel();
        dado1 = new javax.swing.JButton();
        dado2 = new javax.swing.JButton();
        dado3 = new javax.swing.JButton();
        dado4 = new javax.swing.JButton();
        dado5 = new javax.swing.JButton();
        dado6 = new javax.swing.JButton();
        dado7 = new javax.swing.JButton();
        dado8 = new javax.swing.JButton();
        dado9 = new javax.swing.JButton();
        dado10 = new javax.swing.JButton();
        dado11 = new javax.swing.JButton();
        dado12 = new javax.swing.JButton();
        dado13 = new javax.swing.JButton();
        dado14 = new javax.swing.JButton();
        dado15 = new javax.swing.JButton();
        dado16 = new javax.swing.JButton();
        startJogo = new javax.swing.JButton();
        enviaPalavra = new javax.swing.JToggleButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        aPalavras = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        mostrarTexto = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Boggle");
        setBackground(new java.awt.Color(255, 255, 102));
        setMinimumSize(new java.awt.Dimension(600, 480));
        setPreferredSize(new java.awt.Dimension(600, 480));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(22, 44, 111));
        jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 255), 1, true));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        dado1.setBackground(new java.awt.Color(204, 204, 204));
        dado1.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado1MouseClicked(evt);
            }
        });
        dado1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado1ActionPerformed(evt);
            }
        });
        jPanel1.add(dado1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 60, 50));

        dado2.setBackground(new java.awt.Color(204, 204, 204));
        dado2.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado2MouseClicked(evt);
            }
        });
        dado2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado2ActionPerformed(evt);
            }
        });
        jPanel1.add(dado2, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 10, 60, 50));

        dado3.setBackground(new java.awt.Color(204, 204, 204));
        dado3.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado3MouseClicked(evt);
            }
        });
        dado3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado3ActionPerformed(evt);
            }
        });
        jPanel1.add(dado3, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 10, 60, 50));

        dado4.setBackground(new java.awt.Color(204, 204, 204));
        dado4.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado4MouseClicked(evt);
            }
        });
        dado4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado4ActionPerformed(evt);
            }
        });
        jPanel1.add(dado4, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 10, 60, 50));

        dado5.setBackground(new java.awt.Color(204, 204, 204));
        dado5.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado5MouseClicked(evt);
            }
        });
        dado5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado5ActionPerformed(evt);
            }
        });
        jPanel1.add(dado5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 60, 50));

        dado6.setBackground(new java.awt.Color(204, 204, 204));
        dado6.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado6.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado6MouseClicked(evt);
            }
        });
        dado6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado6ActionPerformed(evt);
            }
        });
        jPanel1.add(dado6, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 70, 60, 50));

        dado7.setBackground(new java.awt.Color(204, 204, 204));
        dado7.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado7.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado7MouseClicked(evt);
            }
        });
        dado7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado7ActionPerformed(evt);
            }
        });
        jPanel1.add(dado7, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 70, 60, 50));

        dado8.setBackground(new java.awt.Color(204, 204, 204));
        dado8.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado8.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado8MouseClicked(evt);
            }
        });
        dado8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado8ActionPerformed(evt);
            }
        });
        jPanel1.add(dado8, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 70, 60, 50));

        dado9.setBackground(new java.awt.Color(204, 204, 204));
        dado9.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado9.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado9MouseClicked(evt);
            }
        });
        dado9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado9ActionPerformed(evt);
            }
        });
        jPanel1.add(dado9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, 60, 50));

        dado10.setBackground(new java.awt.Color(204, 204, 204));
        dado10.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado10.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado10MouseClicked(evt);
            }
        });
        dado10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado10ActionPerformed(evt);
            }
        });
        jPanel1.add(dado10, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 130, 60, 50));

        dado11.setBackground(new java.awt.Color(204, 204, 204));
        dado11.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado11.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado11MouseClicked(evt);
            }
        });
        dado11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado11ActionPerformed(evt);
            }
        });
        jPanel1.add(dado11, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 130, 60, 50));

        dado12.setBackground(new java.awt.Color(204, 204, 204));
        dado12.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado12.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado12MouseClicked(evt);
            }
        });
        dado12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado12ActionPerformed(evt);
            }
        });
        jPanel1.add(dado12, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 130, 60, 50));

        dado13.setBackground(new java.awt.Color(204, 204, 204));
        dado13.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado13.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado13.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado13MouseClicked(evt);
            }
        });
        dado13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado13ActionPerformed(evt);
            }
        });
        jPanel1.add(dado13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, 60, 50));

        dado14.setBackground(new java.awt.Color(204, 204, 204));
        dado14.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado14.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado14.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado14MouseClicked(evt);
            }
        });
        dado14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado14ActionPerformed(evt);
            }
        });
        jPanel1.add(dado14, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 190, 60, 50));

        dado15.setBackground(new java.awt.Color(204, 204, 204));
        dado15.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado15.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado15MouseClicked(evt);
            }
        });
        dado15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado15ActionPerformed(evt);
            }
        });
        jPanel1.add(dado15, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 190, 60, 50));

        dado16.setBackground(new java.awt.Color(204, 204, 204));
        dado16.setFont(new java.awt.Font("Arial", 1, 16)); // NOI18N
        dado16.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 204, 204), 2, true));
        dado16.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dado16MouseClicked(evt);
            }
        });
        dado16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dado16ActionPerformed(evt);
            }
        });
        jPanel1.add(dado16, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 190, 60, 50));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 290, 250));

        startJogo.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        startJogo.setText("Iniciar Jogo");
        startJogo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startJogoActionPerformed(evt);
            }
        });
        getContentPane().add(startJogo, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 290, 40));

        enviaPalavra.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/51817.jpg"))); // NOI18N
        enviaPalavra.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                enviaPalavraMouseClicked(evt);
            }
        });
        getContentPane().add(enviaPalavra, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 370, 30, 30));

        aPalavras.setEditable(false);
        aPalavras.setColumns(20);
        aPalavras.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        aPalavras.setRows(5);
        aPalavras.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 204, 255)));
        jScrollPane1.setViewportView(aPalavras);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 80, 190, 250));

        jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel1.setText("Palavras Encontradas");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 60, -1, -1));

        mostrarTexto.setBackground(new java.awt.Color(22, 44, 111));
        mostrarTexto.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        mostrarTexto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(22, 44, 111)));
        getContentPane().add(mostrarTexto, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 370, 290, 30));

        jMenuBar1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        jMenu1.setText("Regras");
        jMenuBar1.add(jMenu1);

        jMenu3.setText("Sobre");
        jMenuBar1.add(jMenu3);

        jMenu2.setText("Sair");
        jMenu2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu2MouseClicked(evt);
            }
        });
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents
   /* public void imagem_fundo(){
        try{
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
           jLabel2.setIcon(new ImageIcon("src/Imagens/preview_imagem1.jpg"));
            add(jLabel2);
            pack();
            this.setExtendedState(MAXIMIZED_BOTH);
        }catch(Exception e){
            JOptionPane.showMessageDialog(rootPane, e, "Error!", 0);
        }
    } */
    private void startJogoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startJogoActionPerformed
        if (jogoAndamento==false){
            StopWatch sw;
            try {
                sw = new StopWatch(this.jLabel1);
            } catch (UnknownHostException ex) {
                Logger.getLogger(Jogo.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Jogo.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Jogo.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        dado1.setVisible(true);dado2.setVisible(true);dado3.setVisible(true);
        dado4.setVisible(true);dado5.setVisible(true);dado6.setVisible(true);
        dado7.setVisible(true);dado8.setVisible(true);dado9.setVisible(true);
        dado10.setVisible(true);dado11.setVisible(true);dado12.setVisible(true);
        dado13.setVisible(true);dado14.setVisible(true);dado15.setVisible(true);
        dado16.setVisible(true);
        enviaPalavra.setVisible(true);mostrarTexto.setVisible(true);
        mostrarTexto.setEnabled(false);
        //mostrarTexto
        //está fazendo com que ao misturar as letras aquela palavra formada já é enviada para lista
        if(jogoAndamento==true){
            enviandoPalavras();
        //jogoAndamento=false;
        }
        
        letras=letraSorteada.Letras();//solicita da classe Letras, as letras sorteadas
        dado1.setEnabled(true);dado2.setEnabled(true);dado3.setEnabled(true);
        dado4.setEnabled(true);dado5.setEnabled(true);dado6.setEnabled(true);
        dado7.setEnabled(true);dado8.setEnabled(true);dado9.setEnabled(true);
        dado10.setEnabled(true);dado11.setEnabled(true);dado12.setEnabled(true);
        dado13.setEnabled(true);dado14.setEnabled(true);dado15.setEnabled(true);
        dado16.setEnabled(true);
        
        
        dado1.setText(letras[0]);dado2.setText(letras[1]);dado3.setText(letras[2]);
        dado4.setText(letras[3]);dado5.setText(letras[4]);dado6.setText(letras[5]);
        dado7.setText(letras[6]);dado8.setText(letras[7]);dado9.setText(letras[8]);
        dado10.setText(letras[9]);dado11.setText(letras[10]);dado12.setText(letras[11]);
        dado13.setText(letras[12]);dado14.setText(letras[13]);dado15.setText(letras[14]);
        dado16.setText(letras[15]);
        jogoAndamento=true;
        
        startJogo.setText("Nova Combinação de Dados!!");
        tempoInicial=System.currentTimeMillis();
   
    }//GEN-LAST:event_startJogoActionPerformed

    private void dado1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado1ActionPerformed
     
    }//GEN-LAST:event_dado1ActionPerformed

    private void dado1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado1MouseClicked
       if (dado1.isEnabled()==true)
            concatenandoPalavras(dado1.getText());
       dado1.setEnabled(false);
       try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado1MouseClicked

    private void dado2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado2MouseClicked
        if (dado2.isEnabled()==true)
            concatenandoPalavras(dado2.getText());
       dado2.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado2MouseClicked

    private void dado2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado2ActionPerformed

    private void dado3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado3MouseClicked
        if (dado3.isEnabled()==true)
            concatenandoPalavras(dado3.getText());
       dado3.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado3MouseClicked

    private void dado3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado3ActionPerformed

    private void dado4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado4MouseClicked
        if (dado4.isEnabled()==true)
            concatenandoPalavras(dado4.getText());
       dado4.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado4MouseClicked

    private void dado4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado4ActionPerformed

    private void dado5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado5MouseClicked
        if (dado5.isEnabled()==true)
            concatenandoPalavras(dado5.getText());
       dado5.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado5MouseClicked

    private void dado5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado5ActionPerformed

    private void dado6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado6MouseClicked
        if (dado6.isEnabled()==true)
            concatenandoPalavras(dado6.getText());
       dado6.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado6MouseClicked

    private void dado6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado6ActionPerformed

    private void dado7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado7MouseClicked
        if (dado7.isEnabled()==true)
            concatenandoPalavras(dado7.getText());
       dado7.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado7MouseClicked

    private void dado7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado7ActionPerformed

    private void dado8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado8MouseClicked
        if (dado8.isEnabled()==true)
            concatenandoPalavras(dado8.getText());
       dado8.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado8MouseClicked

    private void dado8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado8ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado8ActionPerformed

    private void dado9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado9MouseClicked
        if (dado9.isEnabled()==true)
            concatenandoPalavras(dado9.getText());
       dado9.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado9MouseClicked

    private void dado9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado9ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado9ActionPerformed

    private void dado10MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado10MouseClicked
        if (dado10.isEnabled()==true)
            concatenandoPalavras(dado10.getText());
       dado10.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado10MouseClicked

    private void dado10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado10ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado10ActionPerformed

    private void dado11MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado11MouseClicked
        if (dado11.isEnabled()==true)
            concatenandoPalavras(dado11.getText());
       dado11.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado11MouseClicked

    private void dado11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado11ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado11ActionPerformed

    private void dado12MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado12MouseClicked
        if (dado12.isEnabled()==true)
            concatenandoPalavras(dado12.getText());
       dado12.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado12MouseClicked

    private void dado12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado12ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado12ActionPerformed

    private void dado13MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado13MouseClicked
        if (dado13.isEnabled()==true)
            concatenandoPalavras(dado13.getText());
       dado13.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado13MouseClicked

    private void dado13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado13ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado13ActionPerformed

    private void dado14MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado14MouseClicked
        if (dado14.isEnabled()==true)
            concatenandoPalavras(dado14.getText());
       dado14.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado14MouseClicked

    private void dado14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado14ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado14ActionPerformed

    private void dado15MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado15MouseClicked
        if (dado15.isEnabled()==true)
            concatenandoPalavras(dado15.getText());
       dado15.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado15MouseClicked

    private void dado15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado15ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado15ActionPerformed

    private void dado16MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dado16MouseClicked
        if (dado16.isEnabled()==true)
            concatenandoPalavras(dado16.getText());
       dado16.setEnabled(false);
              try {  
            File soundFile = new File("src/music/button-10.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_dado16MouseClicked

    private void dado16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dado16ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dado16ActionPerformed

    private void enviaPalavraMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_enviaPalavraMouseClicked
        aPalavras.append(mostrarTexto.getText() + "\n");
        enviandoPalavras();
        try {  
            File soundFile = new File("src/music/button-9.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        } 
    }//GEN-LAST:event_enviaPalavraMouseClicked

    private void jMenu2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu2MouseClicked
        this.setDefaultCloseOperation(Jogo.EXIT_ON_CLOSE);
        this.setDefaultCloseOperation(Inicio.DISPOSE_ON_CLOSE);
    try {
        Cliente.desconectarServidor();
    } catch (IOException ex) {
        Logger.getLogger(Jogo.class.getName()).log(Level.SEVERE, null, ex);
    }
        this.dispose();
    }//GEN-LAST:event_jMenu2MouseClicked

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        try {  
            File soundFile = new File("src/music/iron-man.wav");  
            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);  
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());  
            Clip clip = (Clip) AudioSystem.getLine(info);  
            clip.open(sound);  
            clip.start();
        } catch (Exception e) {
            Toolkit.getDefaultToolkit().beep(); 
        }        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowActivated
public void concatenandoPalavras(String letra){
  //String palavras = null;
    
             
                if (cont==0){
                    palavras=letra;
                    //status=false;
                    cont++;
                }
                else
                    palavras+=letra;
  mostrarTexto.setText(palavras);

}

/*public void resultadodoJogo() throws IOException, ClassNotFoundException{
   int i=0;
   int contadorPalavras=0;
    i=lista.consultar(true);
    System.out.println("contador "+i);
    conjuntoPalavras=new String [i];
    while (contadorPalavras<i){
        conjuntoPalavras[contadorPalavras]=(String) lista.consultar(contadorPalavras);
        System.out.println("resultadodoJogo "+conjuntoPalavras[contadorPalavras]);
        contadorPalavras++;
    }
    // depois de carregar os dado envia p cliente essa informação
    //conjuntoPalavras=(String[]) lista.consultar();
    System.out.println("conjunto de dados "+ conjuntoPalavras);
   palavrasEnviadas=(String[]) cliente.enviandoDado(conjuntoPalavras);
}*/

/*public void enviandoPalavras(){
   if(!"".equals(mostrarTexto.getText())){
    //System.out.println(contArmazenador+1 +"Palavra digitada " +palavras);
    //armazenadorTemp[contArmazenador]=palavras;
    lista.inserir(palavras,contArmazenador);
    contArmazenador++;
    //mostrarDados.setText(palavras +"\n");
    
    //contArmazenador++;
    mostrarTexto.setText("");
    palavras = "";}
    dado1.setEnabled(true);dado2.setEnabled(true);dado3.setEnabled(true);
        dado4.setEnabled(true);dado5.setEnabled(true);dado6.setEnabled(true);
        dado7.setEnabled(true);dado8.setEnabled(true);dado9.setEnabled(true);
        dado10.setEnabled(true);dado11.setEnabled(true);dado12.setEnabled(true);
        dado13.setEnabled(true);dado14.setEnabled(true);dado15.setEnabled(true);
        dado16.setEnabled(true);
  
   
    
}*/
public void fecharframe(){
  this.setDefaultCloseOperation(Jogo.EXIT_ON_CLOSE);  
}
public void enviandoPalavras(){
   if(!"".equals(mostrarTexto.getText())){
       Letras.ArmazenarListaPalavras(palavras, contArmazenador);
       //letraSorteada.ArmazenarListaPalavras(palavras, contArmazenador);
    contArmazenador++;
    //mostrarDados.setText(palavras +"\n");
    
    //contArmazenador++;
    mostrarTexto.setText("");
    palavras = "";}
    dado1.setEnabled(true);dado2.setEnabled(true);dado3.setEnabled(true);
        dado4.setEnabled(true);dado5.setEnabled(true);dado6.setEnabled(true);
        dado7.setEnabled(true);dado8.setEnabled(true);dado9.setEnabled(true);
        dado10.setEnabled(true);dado11.setEnabled(true);dado12.setEnabled(true);
        dado13.setEnabled(true);dado14.setEnabled(true);dado15.setEnabled(true);
        dado16.setEnabled(true);
  
   
    
}

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Jogo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Jogo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Jogo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Jogo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    new Jogo().setVisible(true);
                } catch (UnknownHostException ex) {
                    Logger.getLogger(Jogo.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(Jogo.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Jogo.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea aPalavras;
    private javax.swing.JButton dado1;
    private javax.swing.JButton dado10;
    private javax.swing.JButton dado11;
    private javax.swing.JButton dado12;
    private javax.swing.JButton dado13;
    private javax.swing.JButton dado14;
    private javax.swing.JButton dado15;
    private javax.swing.JButton dado16;
    private javax.swing.JButton dado2;
    private javax.swing.JButton dado3;
    private javax.swing.JButton dado4;
    private javax.swing.JButton dado5;
    private javax.swing.JButton dado6;
    private javax.swing.JButton dado7;
    private javax.swing.JButton dado8;
    private javax.swing.JButton dado9;
    private javax.swing.JToggleButton enviaPalavra;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel mostrarTexto;
    private javax.swing.JButton startJogo;
    // End of variables declaration//GEN-END:variables
}
